import { ref } from "vue";
import { SparePartApplyDetail } from '../types'
import apiParts from "@/util/network_api/parts";

/**
 * 配件申请单详情
 */ 
export default function () {
	const sparePartAPplyDetail = ref<SparePartApplyDetail>({
		id: "",
		code: "",
		saleNo: "",
		networkId: "",
		networkName: "",
		factory: "",
		status: 1,
		type: 1,
		receivingStoreId: "",
		receivingStoreName: "",
		shippingStoreId: "",
		shippingStoreName: "",
		contactName: "",
		contactPhone: "",
		orderRemark: "",
		province: "",
		city: "",
		area: "",
		town: "",
		detailAddress: "",
		createType: 1,
		creator: "",
		createTime: "",
		updateTime: "",
		freezeAmount: 0,
		isPosting: 0,
		materialApplyVoList: [],
		spareApplyOrderLogList: []
	})
	
	const getSparePartApplyDetail = async (id: string) => {
		try {
			const res = await apiParts.getSparePartApplyDetail(id)
			if (res.code === 20000) {
				sparePartAPplyDetail.value = res.data.row
				return ''
			}
			
			return res.message
		} catch (e) {
			return '获取配件申请单详情失败，请稍后重试'
		}
	}
	
	return {
		sparePartAPplyDetail,
		getSparePartApplyDetail,
	}
}